package com.example.dollycontrol;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Handler;

public class DollyTimer {
	
	private DollySlider dollyRepresentation;
	private Timer dollyTimer;
	private Handler handlerUI;
	
	/* constructor*/
	public DollyTimer(DollySlider dollyRepresentation, Handler handlerUI){
		this.dollyRepresentation = dollyRepresentation;
		this.handlerUI = handlerUI;
	}
	
	public void launchTimer(int delay, final int period){
		dollyTimer = new Timer();
		dollyTimer.scheduleAtFixedRate(new TimerTask() {
			public void run() {
				handlerUI.post(
					new Runnable(){
						public void run() {
							dollyRepresentation.dollyStep(period);	
						}
					}
				);
			}
		}, delay, period);
	}
			
	public void setDollyRepresentation(DollySlider dollySlider){
		this.dollyRepresentation = dollySlider; 
	}
		
	public Timer getTimer(){
		return this.dollyTimer;
	}
}
